﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Quizz.Library.Actions;
using Quizz.Library.Filter;
using Quizz.Infrastructure;
using Quizz.Library.Controller;
using Quizz.Library.QuizzServiceReference;

namespace Quizz.Web.FrontEnd.Controllers
{
    public class QuestionController : BaseController
    {
        //
        // GET: /Question/
        [EditorFilter]
        public ActionResult Index()
        {
            ViewData[Constants.QuestionListCurrent] = Session[Constants.QuestionListCurrent];
            ViewData[Constants.QuestionListKeyword] = Session[Constants.QuestionListKeyword];
            ViewData[Constants.QuestionListOrder] = Session[Constants.QuestionListOrder];
            return View();
        }

        //
        // POST: /Question/Add/
        [HttpPost]
        [EditorFilter(IsAjax=true)]
        [ValidateInput(false)]
        public ActionResult Add(Question question)
        {
            return new QuestionAction(this).Add(question);
        }


        //
        // POST : GetPage
        [HttpPost]
        [EditorFilter(IsAjax = true)]
        public JsonResult GetPage(long subjectId, int page, int count, string orderCol)
        {
            return new QuestionAction(this).GetPage(subjectId, page, count, orderCol);
        }

        //
        // POST : Get
        [HttpPost]
        [EditorFilter(IsAjax=true)]
        public JsonResult Get(long id){
            return new QuestionAction(this).Get(id);
        }

        //
        // POST : Delete
        [EditorFilter(IsAjax = true)]
        [HttpPost]
        public JsonResult Delete(long id)
        {
            return new QuestionAction(this).Delete(id);
        }

        //
        // POST : View
        [HttpPost]
        [EditorFilter(IsAjax = true)]
        public JsonResult View(long id)
        {
            return new QuestionAction(this).View(id);
        }

        //
        // POST : Create
        [HttpPost]
        [EditorFilter(IsAjax = true)]
        public JsonResult Create(int type)
        {
            return new QuestionAction(this).Create(type);
        }

        //
        // POST : Update
        [HttpPost]
        [EditorFilter(IsAjax = true)]
        [ValidateInput(false)]
        public JsonResult Update(Question question)
        {
            return new QuestionAction(this).Update(question);
        }

        #region Overrive methods

        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);
            CreateMenu(Constants.MenuManage);
        }

        #endregion
    }
}
